package com.yphone.ui.login.presenter;

import android.text.TextUtils;

import com.iiordanov.bVNC.App;
import com.yphone.net.IUIDataListener;
import com.yphone.net.bean.BaseResultWrapper;
import com.yphone.tools.MyLog;
import com.yphone.ui.dialog.CommSmallLoadingDialog;
import com.yphone.ui.login.bean.request.VerifiCodeRequestInfo;
import com.yphone.ui.login.bean.respone.VerifiCodeResponeInfo;
import com.yphone.ui.login.contract.VerifiViewContract;
import com.yphone.ui.login.model.VerifiViewModel;
import com.yphone.utils.ToastUtils;
import com.zzkj.yunphone.R;

public class VerifiViewPresenter implements VerifiViewContract.IPresenter {
    private IUIDataListener iuiDataListener = new IUIDataListener() {
        public void uiDataSuccess(Object object) {
            BaseResultWrapper<String> userinfoWrapper = (BaseResultWrapper) object;
            if (userinfoWrapper == null){
                CommSmallLoadingDialog.dismissDialog();
                ToastUtils.showLong(App.getContext().getString(R.string.server_error));
                return;
            }
            if ( userinfoWrapper.code != 1 || !userinfoWrapper.success.equals("true")) {
                if (!TextUtils.isEmpty(userinfoWrapper.msg)) {
                    ToastUtils.showLong((CharSequence) userinfoWrapper.msg);
                }
                CommSmallLoadingDialog.dismissDialog();
                return;
            }
            MyLog.d(VerifiViewPresenter.class.getSimpleName(), "验证码获取成功！");
            if (!TextUtils.isEmpty(userinfoWrapper.msg)) {
                ToastUtils.showLong((CharSequence) userinfoWrapper.msg);
            }
            CommSmallLoadingDialog.dismissDialog();
        }

        public void uiDataError(Exception error) {
            MyLog.d(VerifiViewPresenter.class.getSimpleName(), "验证码获取异常！");
            CommSmallLoadingDialog.dismissDialog();
        }
    };
    private VerifiViewContract.IView mIView;
    private VerifiViewModel mModel;

    public VerifiViewPresenter(VerifiViewContract.IView IView) {
        this.mIView = IView;
        this.mModel = new VerifiViewModel();
    }

    public void getVerifiCationCode(VerifiCodeRequestInfo info, int getVerifiCodeType) {
        this.mModel.requestVerifiCode(this.iuiDataListener, info, getVerifiCodeType);
    }

    public void start() {
    }

    public void destory() {
        this.mModel.destory();
    }
}